package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Goal;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class GoalDao {
	private DBHelp<Goal> db = new DBHelp<Goal>();
	public List<Goal> findByProjectId(int projectid){
		String sql="SELECT id,`name`,description,dangqianjindu,projectid,userid FROM t_goal WHERE projectid=?";
		return db.executeQueryForList(sql, new GoalRowMapper(), projectid);
	}
	private class GoalRowMapper implements RowMapper<Goal>{

		public Goal mapperRow(ResultSet rs) throws SQLException {
			// TODO Auto-generated method stub
			Goal g = new Goal();
			g.setDangqianjindu(rs.getString("dangqianjindu"));
			g.setDescription(rs.getString("description"));
			g.setGoalID(rs.getInt("id"));
			g.setGoalName(rs.getString("name"));
			g.setProjectID(rs.getInt("projectID"));
			g.setUserID(rs.getInt("userID"));
			
			return g;
		}
		
	}
}
